package com.freesky.web.manager.controller.panel;

import com.freesky.common.dao.entity.Panel;
import com.freesky.common.pojo.ZTreeNode;
import com.freesky.common.utils.reponse.JSONResponse;
import com.freesky.web.manager.remote.panel.HomePanelRemote;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 陈玉林
 * @modifiedBy:
 * @date: Create In 8:54 2018/12/13
 * @description:
 */
@Controller
@Api(description = "首页板块")
public class HomePanelController {
    @Autowired
    private HomePanelRemote remote;

    @ApiOperation(value = "进入界面-首页版块列表")
    @GetMapping("/home/panel/page")
    public String page() {
        return "home-panel/list";
    }

    @ApiOperation(value = "进入界面-首页版块添加")
    @GetMapping(value = "/home/panel/add/page")
    public String addPage() {
        return "home-panel/add";
    }

    @ResponseBody
    @PostMapping(value = "/home/panel/add")
    @ApiOperation(value = "首页添加板块")
    public JSONResponse add(@ModelAttribute Panel panel) {
        return remote.add(panel);
    }

    @ResponseBody
    @GetMapping(value = "/home/panel/list")
    @ApiOperation(value = "首页板块列表")
    public List<ZTreeNode> list() {
        return remote.list();
    }


    @ResponseBody
    @PostMapping(value = "/home/panel/update")
    @ApiOperation(value = "首页板块编辑")
    public JSONResponse update(@ModelAttribute Panel panel) {
        return remote.update(panel);
    }

    @ResponseBody
    @DeleteMapping(value = "/home/panel/del/{id}")
    @ApiOperation(value = "首页版块删除")
    public JSONResponse delete(@PathVariable(value = "id") int id) {
        return remote.delete(id);
    }
}
